package com.qf.service.Impl;

import com.qf.mapper.AppInfoMapper;
import com.qf.pojo.AppInfo;
import com.qf.service.AppInfoService;
import com.qf.vo.AppDownloadsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AppInfoServiceImpl implements AppInfoService {

    @Autowired
    private AppInfoMapper appInfoMapper;



    @Override
    public List<AppDownloadsVO> findAppDownloadTopFive() {
        //1. 调用mapper查询数据AppInfo
        List<AppInfo> appInfoList = appInfoMapper.findSoftwareNameAndDownloadsTopFive();
        //2. 将数据封装到List<AppDownloadsVO>
        List<AppDownloadsVO> data = new ArrayList<>();
        for (AppInfo appInfo : appInfoList) {
            AppDownloadsVO vo = new AppDownloadsVO(appInfo.getSoftwareName(),appInfo.getDownloads());
            data.add(vo);
        }
        //3. 返回.
        return data;
    }
}
